#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <climits>
#include <set>
#include <iterator>
#include <map>
#include <vector>
#include <list>
#include <stack>
#include <string>
#include <iostream>
#include <algorithm>
#include <numeric>
//#pragma comment(linker, "/STACK:16777216")
using namespace std;
const double pi = 3.14159265358979324;
template <class T>  T gcd(T a, T b){ return b? gcd(b, a % b) : a;}
template <class T>  T lcm(T a, T b){ return a / gcd(a,b) * b;}
typedef long long ll;
vector<long long> qqq;

int main(){
    for (int i = 1; i <= 5; ++i){
        string x = "";
        for (int j = 1; j <= i; ++j)
            x += "4";
        for (int j = 1; j <= i; ++j)
            x += "7";
        do {
            ll cur = 0;
            for (int cc = x.length() - 1; cc >= 0; --cc){
                cur  = cur * 10  + x[cc] - '0';
            }
            qqq.push_back(cur);
        }while (next_permutation(x.begin(), x.end()));
    }
    sort(qqq.begin(), qqq.end());
    ll x;
    cin>>x;
    cout << *lower_bound(qqq.begin(), qqq.end(), x);
    return 0;
}